package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysRetailMapper;
import com.ruoyi.system.domain.SysRetail;
import com.ruoyi.system.service.ISysRetailService;

/**
 * 散户信息管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-22
 */
@Service
public class SysRetailServiceImpl implements ISysRetailService
{
    @Autowired
    private SysRetailMapper sysRetailMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询散户信息管理
     *
     * @param rId 散户信息管理主键
     * @return 散户信息管理
     */
    @Override
    public SysRetail selectSysRetailByRId(Long rId)
    {
        return sysRetailMapper.selectSysRetailByRId(rId);
    }

    /**
     * 查询散户信息管理列表
     *
     * @param sysRetail 散户信息管理
     * @return 散户信息管理
     */
    @Override
    public List<SysRetail> selectSysRetailList(SysRetail sysRetail)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = sysUserMapper.selectUserById(loginUser.getUserId());
        sysRetail.setSupplierId(user.getSupplierId());
        return sysRetailMapper.selectSysRetailList(sysRetail);
    }

    /**
     * 新增散户信息管理
     *
     * @param sysRetail 散户信息管理
     * @return 结果
     */
    @Override
    public int insertSysRetail(SysRetail sysRetail)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = sysUserMapper.selectUserById(loginUser.getUserId());
        sysRetail.setSupplierId(user.getSupplierId());
        return sysRetailMapper.insertSysRetail(sysRetail);
    }

    /**
     * 修改散户信息管理
     *
     * @param sysRetail 散户信息管理
     * @return 结果
     */
    @Override
    public int updateSysRetail(SysRetail sysRetail)
    {
        return sysRetailMapper.updateSysRetail(sysRetail);
    }

    /**
     * 批量删除散户信息管理
     *
     * @param rIds 需要删除的散户信息管理主键
     * @return 结果
     */
    @Override
    public int deleteSysRetailByRIds(Long[] rIds)
    {
        return sysRetailMapper.deleteSysRetailByRIds(rIds);
    }

    /**
     * 删除散户信息管理信息
     *
     * @param rId 散户信息管理主键
     * @return 结果
     */
    @Override
    public int deleteSysRetailByRId(Long rId)
    {
        return sysRetailMapper.deleteSysRetailByRId(rId);
    }

    /**
     * 修改散户状态
     *
     * @param sysRetail 散户信息管理
     * @return 结果
     */
    @Override
    public int updateSysRetailStatus(SysRetail sysRetail) {
        return sysRetailMapper.updateSysRetail(sysRetail);
    }

}
